package com.lc;

import com.lc.constants.HttpConstants;
import com.lc.handler.ProtocolUtil;
import com.lc.mode.Request;
import com.lc.mode.Response;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Date;

/**
 * @author liuc
 * @date 2021/5/5
 * @description 处理业务
 **/
public class Worker implements Runnable{

    private SocketChannel channel;

    public Worker(SocketChannel channel){
        this.channel = channel;
    }

    @Override
    public void run() {
        if(channel.isOpen()){
            ByteBuffer buffer = ByteBuffer.allocate(1024);
            try {
                channel.read(buffer);
                buffer.flip();
                byte[] content = new byte[buffer.limit()];
                //读到字节数组中
                buffer.get(content);
                Request request = new Request(content);
                Response response = new Response(channel);
                response.write("hello!");
                buffer.clear();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
